/*****************************************************
Copyright (C) 2020. All rights reserved.
File name     ：TestMain.c
Version       ：v1.0
Author        ：zhengqijun
Date          ：2020-04-08
Function List ：
Description   ：main function
******************************************************/

#include <stdio.h>  // for printf
#include "SkewHeap.h"

#define MaxSize (50)

// PrintSkewHeap for testing
static void PrintDepth(ElementType X, int depth);
static void PrintSkewHeap(PriorityQueue H, int depth);

void PrintDepth(ElementType X, int depth) {
    while (depth > 0) {
        printf("    ");
        --depth;
    }
    printf("%02d\n", X);
}

void PrintSkewHeap(PriorityQueue H, int depth) {
    if (H == NULL) {
        printf("PriorityQueue is empty!\n");
        return;
    }

    if (Right(H) != NULL) {
        PrintSkewHeap(Right(H), depth + 1);
    }

    PrintDepth(Retrieve(H), depth);

    if (Left(H) != NULL) {
        PrintSkewHeap(Left(H), depth + 1);
    }
}

// main function
int main(void) {
    PriorityQueue H;
    int i;
    int j;

    H = Initialize();

    if (H == NULL) {
        printf("PriorityQueue is empty!\n");
    } else {
        printf("PriorityQueue is not empty!\n");
    }

    printf("Insert priority queue: [ ");
    for (i = 1, j = MaxSize / 2; i < MaxSize; i += 3) {
        printf("%02d ", j);
        Insert(j, H);
        j = (j + 21) % MaxSize;
    }
    printf("]\n");

    printf("Print priority queue:\n");
    PrintSkewHeap(H, 0);
    printf("\n");

    printf("Find min element is %d in priority queue!\n", FindMin(H));
    printf("Delete min element is %d in priority queue!\n", Retrieve(DeleteMin(H)));

    printf("Print priority queue:\n");
    PrintSkewHeap(H, 0);
    printf("\n");

    H = Destroy(H);

    return 0;
}

// EOF

